<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>await</title>
  </head>
  <body>
    <script>
      let main = async () => {
        //await 右侧为其他类型的值
        // let res = await 123;
        //await 右侧为 promise 数据.  await 等待
        try {
          let res = await new Promise((resolve, reject) => {
            // resolve('OKOKOK');
            setTimeout(() => {
              // resolve('SUCCESS');
              reject("Fail");
            }, 1000);
          });
          //获取成功的结果值   ->  这里相当于是 then 方法成功的回调
          console.log(res);
        } catch (e) {
          //获取失败的结果值   ->  这里相当于是 then 方法失败的回调
          console.log(e);
        }
      };

      main();
    </script>
  </body>
</html>
